import { Component, OnInit, Input, ViewChild, EventEmitter, Output, ElementRef } from '@angular/core';
import { SFSchema, SFComponent } from '@delon/form';
import { HttpService } from 'lbf';
import { NzMessageService, NzModalService } from 'ng-zorro-antd';
import { LbStepsComponent } from '@shared/components/lb-steps/lb-steps.component';

@Component({
  selector: 'lb-bzt-info',
  templateUrl: './lb_bzt_info.component.html',
  styleUrls: ['./lb_bzt_info.component.less']
})
export class LbBztInfoComponent implements OnInit {
  @Input() set stepsNodes(value) {
    this._stepsNodes = value

    this.step.stepsNodes = value;
  }
  get stepsNodes() {
    return this._stepsNodes
  }
  _stepsNodes

  @Input() set showHjInfo(value) {
    this._showHjInfo = value

    this.isShowInfo = value;
  }
  get showHjInfo() {
    return this._showHjInfo
  }
  _showHjInfo

  @Input() hjInfo = {}

  isShowInfo = false;
  @ViewChild('step', { static: true }) step: LbStepsComponent;
  @ViewChild('view', { static: false }) view: ElementRef;
  @Output() ok = new EventEmitter<string>();

  showStepWindow = false;
  rect;
  lock;
  isRight= false
  ngOnInit() {
    this.isShowInfo = false;
    this.initBzt();
  }

  initBzt() {
    this.step.stepsNodes = this.stepsNodes;
  }


  handleClick(res: any) {
    this.ok.emit(res);
    this.lock = false
  }
  click($event: MouseEvent) {
    console.log(window)
    if (this.showHjInfo) {
      // console.log(this.view.nativeElement)
      // console.log('offsetLeft',this.view.nativeElement.getBoundingClientRect() )
      let rect = this.view.nativeElement.getBoundingClientRect()
      if (!this.lock) {
        let element = this.view.nativeElement.style
        if ($event.screenX + rect.width > window.outerWidth) {
          element.left = $event.screenX - rect.width + 'px'
          this.isRight=true
        } else {
          element.left = $event.screenX + 10 + 'px';
          this.isRight=false
        }
        if ($event.clientY + rect.height > window.innerHeight) {
          element.top = window.innerHeight - rect.height + 'px'
        } else {
          element.top = $event.clientY + 30 + 'px';
        }

      } else {
        this.showHjInfo = false
      }
      this.lock = true
      // console.log($event)
    }
  }


  closeWindow() {
    this.showStepWindow = false;
  }



  constructor(private lbs: HttpService,
    private modalService: NzModalService,
    public msgSrv: NzMessageService) { }
}
